package businesslogic.plan;

import java.rmi.RemoteException;
import java.util.ArrayList;

import po.planpo.PlanPO;

import dataService.planDataService.PlanDataService;

import vo.Limitation;
import vo.publishplanvo.PlanVO;
import Enum.Factor;
import Enum.ResultMessage;
import businesslogicservice.planblservice.PublishPlanBLService;


public class PublishPlan implements PublishPlanBLService{
	public ResultMessage setInformation(PlanVO planVO)  throws RemoteException{
		ResultMessage result;
		PlanPO planPO = new PlanPO(planVO.getPlan(), planVO.getFaculty());
		PlanDataService planDataService = new PlanDataService();
		Factor factor = Factor.Faculty;
		String value = planVO.getFaculty().toString();
		Limitation limitation = new Limitation(factor, value);
		ArrayList<Limitation> limitations = new ArrayList<Limitation>();
		limitations.add(limitation);
		PlanVO planVO2 = planDataService.get(limitations);
		if(planVO2==null){
			//insert
			result = planDataService.insert(planPO);
		}
		else{
			//update
			result = planDataService.update(planPO);
		}
		return result;
	}
}
